export function __getLocal(value) {
  const session = localStorage.getItem(value)
  return session
}
export function __setLocal(key, value) {
  try {
    window.localStorage.setItem(`${key}`, value)
    return true
  } catch (error) {
    return false
  }
}
export function _removeLocal(key) {
  try {
    window.localStorage.removeItem(`${key}`)
    return true
  } catch (error) {
    return false
  }
}

// 判断变量是否为空
export function isNotEmpty(obj) {
  if (typeof obj === 'undefined' || obj == null) {
    return false
  }
  if (typeof obj === 'function') {
    return true
  }
  if (obj.constructor == Number) {
    if (obj) {
      return true
    }
    return false
  }
  if (typeof obj === 'string') {
    if (obj !== '') {
      return true
    }
    return false
  }
  return Object.keys(obj).length > 0
}
/**
 * 解析 url 中的参数
 * @param url
 * @returns {Object}
 */
export function parseUrlParams(url) {
  const params = {}
  if (!url || url === '' || typeof url !== 'string') {
    return params
  }
  const paramsStr = url.split('?')[1]
  if (!paramsStr) {
    return params
  }
  const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
  for (let i = 0; i < paramsArr.length / 2; i++) {
    const value = paramsArr[i * 2 + 1]
    params[paramsArr[i * 2]] = value === 'true' ? true : value === 'false' ? false : value
  }
  return params
}
export const formatColumn = (text, record) => {
  if (!isEmpty(text)) {
    return text
  }
  return '-'
}

export const isEmpty = (value) => {
  let _value = value
  try {
    _value = value.trim()
  } catch (error) {
    //
  }
  return !_value && _value !== 0
}
// 滚动到元素顶部
export function scrollToElement(id) {
  const element = document.getElementById(id)
  element.scrollIntoView()
}
